package user.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import java.awt.Font;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.ImageIcon;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class SystemAdminFrame extends JFrame {

	private JPanel contentPane;
	private JMenu UserNameText;
	private static String loginName = null;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					SystemAdminFrame frame = new SystemAdminFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public SystemAdminFrame() {
		setTitle("系统管理员主界面");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 800, 750);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		UserNameText = new JMenu("用户名");
		loginName = LoginFrame.adminName();
		UserNameText.setText(loginName);
		UserNameText.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
		UserNameText.setIcon(new ImageIcon(MainFrame.class.getResource("/images/用户2.png")));
		menuBar.add(UserNameText);
		
		JMenuItem menuItem2 = new JMenuItem("退出登录");
		menuItem2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int x = JOptionPane.showConfirmDialog(null, "是否退出登录");
				if(x==0) {//退出为0
					new LoginFrame().setVisible(true);
					dispose();
				}
			}
		});
		
		JMenuItem mntmNewMenuItem = new JMenuItem("用户管理");
		mntmNewMenuItem.setIcon(new ImageIcon(SystemAdminFrame.class.getResource("/images/注册.png")));
		mntmNewMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new UserManagerFrame().setVisible(true);
			}
		});
		mntmNewMenuItem.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 17));
		UserNameText.add(mntmNewMenuItem);
		menuItem2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 17));
		menuItem2.setIcon(new ImageIcon(SystemAdminFrame.class.getResource("/images/退出.png")));
		UserNameText.add(menuItem2);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		this.setLocationRelativeTo(null);
		setContentPane(contentPane);
		
		JButton Button = new JButton("用户管理");
		Button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new UserManagerFrame().setVisible(true);
			}
		});
		Button.setFont(new Font("宋体", Font.PLAIN, 35));
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(191)
					.addComponent(Button, GroupLayout.PREFERRED_SIZE, 385, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(196, Short.MAX_VALUE))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(235)
					.addComponent(Button, GroupLayout.PREFERRED_SIZE, 183, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(249, Short.MAX_VALUE))
		);
		contentPane.setLayout(gl_contentPane);
		ImageIcon icon = new ImageIcon("src/images/systemadmin.png");
		JLabel background = new JLabel(icon);
		this.getLayeredPane().setLayout(null);
		contentPane.setOpaque(false);
		background.setBounds(0,0,800,750);
		this.getLayeredPane().add(background,new Integer(Integer.MIN_VALUE));
	}
}
